package cn.edu.guet.config;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.HandlerInterceptor;
//就是拦截器
public class SessionInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2) throws Exception {
        System.out.println(arg0.getRequestURI());
        //普通路径放行
        if ("/yanzheng".equals(arg0.getRequestURI()) || "/html/login/index".equals(arg0.getRequestURI()) ||"/main".equals(arg0.getRequestURI())) { return true;}
        //权限路径拦截
        Object object = arg0.getSession().getAttribute("userid");
        if (null == object) {
            arg1.sendRedirect("/login");
            return false;
        }
        return true;
    }
}